package o;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.icu.text.ListFormatter;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.service.notification.StatusBarNotification;
import android.text.TextUtils;
import androidx.core.app.NotificationCompat.d;
import com.huawei.appmarket.service.alarm.control.RepeatingTaskManager;
import com.huawei.appmarket.service.externalapi.view.ThirdApiActivity;
import com.huawei.secure.android.common.intent.SafeBundle;
import java.util.List;
import java.util.Locale;
import o.ewm.e;
import o.ewm.i;
import o.ewm.n;

public class eds {
    public static void ˋ(Context context, List<String> list) {
        int size = list.size();
        if (size > 0) {
            if (dss.ॱ().ˊ()) {
                ˎ(context);
                Logger.ˎ("PreDlNotificationUtils", "not show updating notification because user turn off switch of update notification");
            } else if (edl.ˏ().ˏॱ()) {
                NotificationManager notificationManager = (NotificationManager) context.getSystemService("notification");
                if (notificationManager == null) {
                    Logger.e("PreDlNotificationUtils", "can not get NotificationManager");
                    return;
                }
                d dVar = new d(context);
                dVar.ˏ(false);
                dVar.ˊ(true);
                dVar.ˎ(null);
                dVar.ˏ(-1);
                dVar.ˊ(e.ॱ);
                dVar.ˏ(null);
                Intent intent = new Intent(context, ThirdApiActivity.class);
                intent.setAction("com.huawei.appmarket.appmarket.intent.action.appmanager");
                dVar.ˎ(PendingIntent.getActivity(context, 20200108, intent, 268435456));
                CharSequence quantityString = context.getResources().getQuantityString(i.ʿ, size, new Object[]{Integer.valueOf(size)});
                CharSequence charSequence = "";
                try {
                    charSequence = String.format(Locale.ENGLISH, edl.ˏ().ॱˊ(), new Object[]{Integer.valueOf(size)});
                } catch (Exception e) {
                    Logger.ˎ("PreDlNotificationUtils", "format string error: " + e.toString());
                }
                CharSequence format = VERSION.SDK_INT >= 26 ? ListFormatter.getInstance().format(list) : "";
                CharSequence ᐝॱ = edl.ˏ().ᐝॱ();
                if (ˋ()) {
                    if (TextUtils.isEmpty(charSequence)) {
                        dVar.ˏ(quantityString);
                    } else {
                        dVar.ˏ(charSequence);
                    }
                    if (TextUtils.isEmpty(ᐝॱ)) {
                        dVar.ˊ(format);
                    } else {
                        dVar.ˊ(ᐝॱ);
                    }
                } else {
                    dVar.ˏ(quantityString);
                    dVar.ˊ(format);
                }
                ॱ(context, notificationManager, dVar);
            } else {
                ˎ(context);
                Logger.ˎ("PreDlNotificationUtils", "not show updating notification because the flag is set off");
            }
        }
    }

    public static void ˏ(Context context, int i) {
        if (i <= 0) {
            ˎ(context);
        } else if (dss.ॱ().ˊ()) {
            Logger.ˎ("PreDlNotificationUtils", "not show updating notification because user turn off switch of update notification");
            ˎ(context);
        } else if (edl.ˏ().ʻॱ()) {
            NotificationManager notificationManager = (NotificationManager) context.getSystemService("notification");
            if (notificationManager == null) {
                Logger.e("PreDlNotificationUtils", "can not get NotificationManager");
                return;
            }
            d dVar = new d(context);
            dVar.ˏ(true);
            dVar.ˊ(false);
            dVar.ˎ(null);
            dVar.ˏ(-1);
            dVar.ˊ(e.ॱ);
            dVar.ˏ(null);
            Intent intent = new Intent(context, ThirdApiActivity.class);
            intent.setAction("com.huawei.appmarket.service.externalapi.actions.AppUninstallAction");
            intent.setFlags(268435456);
            dVar.ˎ(PendingIntent.getActivity(context, 20200108, intent, 268435456));
            int ˊ = i + ˊ(notificationManager);
            CharSequence quantityString = context.getResources().getQuantityString(i.ʽॱ, ˊ, new Object[]{Integer.valueOf(ˊ)});
            CharSequence charSequence = "";
            try {
                charSequence = String.format(Locale.ENGLISH, edl.ˏ().ॱˎ(), new Object[]{Integer.valueOf(ˊ)});
            } catch (Exception e) {
                Logger.ˎ("PreDlNotificationUtils", "format string error: " + e.toString());
            }
            CharSequence ॱᐝ = edl.ˏ().ॱᐝ();
            if (ˋ()) {
                if (TextUtils.isEmpty(charSequence)) {
                    dVar.ˏ(quantityString);
                } else {
                    dVar.ˏ(charSequence);
                }
                if (!TextUtils.isEmpty(ॱᐝ)) {
                    dVar.ˊ(ॱᐝ);
                }
            } else {
                dVar.ˏ(quantityString);
            }
            Bundle bundle = new Bundle();
            bundle.putInt("update_size", ˊ);
            dVar.ˎ(bundle);
            ˊ(context, notificationManager, dVar);
        } else {
            Logger.ˎ("PreDlNotificationUtils", "not show finish update notification because the flag is set off");
            ˎ(context);
        }
    }

    private static boolean ˋ() {
        if (doi.ॱ().equals(HcridSession.ˋ().ˎ())) {
            return true;
        }
        Logger.ˎ("PreDlNotificationUtils", "language is not matched");
        return false;
    }

    private static int ˊ(NotificationManager notificationManager) {
        int i = 0;
        if (VERSION.SDK_INT >= 23) {
            try {
                StatusBarNotification[] activeNotifications = notificationManager.getActiveNotifications();
                if (activeNotifications != null) {
                    for (StatusBarNotification statusBarNotification : activeNotifications) {
                        if (statusBarNotification != null && statusBarNotification.getId() == 20200108) {
                            i = new SafeBundle(statusBarNotification.getNotification().extras).getInt("update_size");
                        }
                    }
                }
            } catch (SecurityException e) {
                Logger.ˎ("PreDlNotificationUtils", "getActiveNotifications SecurityException");
            } catch (Exception e2) {
                Logger.ˎ("PreDlNotificationUtils", "getActiveNotifications Exception");
            }
        }
        return i;
    }

    private static void ˎ(Context context) {
        NotificationManager notificationManager = (NotificationManager) context.getSystemService("notification");
        if (notificationManager != null && ˊ(notificationManager) == 0) {
            notificationManager.cancel(20200108);
        }
    }

    private static void ˊ(Context context, NotificationManager notificationManager, d dVar) {
        if (VERSION.SDK_INT >= 26) {
            NotificationChannel notificationChannel = new NotificationChannel("download.notification.channel", context.getString(n.ʻـ), 3);
            notificationChannel.enableVibration(false);
            notificationChannel.setSound(null, null);
            if (notificationManager.getNotificationChannel(notificationChannel.getId()) == null) {
                notificationManager.createNotificationChannel(notificationChannel);
            }
            dVar.ˋ(notificationChannel.getId());
        }
        notificationManager.notify(20200108, dVar.ˊ());
    }

    private static void ॱ(Context context, NotificationManager notificationManager, d dVar) {
        if (VERSION.SDK_INT >= 26) {
            NotificationChannel notificationChannel = new NotificationChannel("download.notification.channel", context.getString(n.ʻـ), 3);
            notificationChannel.enableVibration(false);
            notificationChannel.setSound(null, null);
            if (notificationManager.getNotificationChannel(notificationChannel.getId()) == null) {
                notificationManager.createNotificationChannel(notificationChannel);
            }
            dVar.ˋ(notificationChannel.getId());
        }
        RepeatingTaskManager repeatingTaskManager = dpw.ˏ().ˎ;
        if (repeatingTaskManager != null) {
            repeatingTaskManager.startForeground(20200108, dVar.ˊ());
            return;
        }
        Logger.ˎ("PreDlNotificationUtils", "Service is null, can't start foreground service");
        notificationManager.notify(20200108, dVar.ˊ());
    }

    public static void ˏ() {
        RepeatingTaskManager repeatingTaskManager = dpw.ˏ().ˎ;
        if (repeatingTaskManager != null && VERSION.SDK_INT >= 24) {
            repeatingTaskManager.stopForeground(2);
        }
    }
}
